<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
	<th:block th:include="include :: header('新增用户')"/>
	<th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
	<form id="form-user-add" class="form-horizontal text-center">
		<input name="deptId" type="hidden" id="treeId"/>
		<h4 class="form-header h4">基本信息</h4>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label is-required">用户编号：</label>
					<div class="col-sm-8">
						<input name="userCode" placeholder="用户编号" class="form-control" type="text" maxlength="30"
						       required>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label is-required">用户名称：</label>
					<div class="col-sm-8">
						<input name="userName" placeholder="请输入用户名称" class="form-control" type="text" maxlength="30"
						       required>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label is-required">性别:</label>
					<div class="radio">
						<label>
							<input type="radio" checked="" value="option1" id="optionsRadios1"
							       name="userSex" th:value="1">男</label>
						<label>
							<input type="radio" value="option2" id="optionsRadios2" name="userSex"
							       th:value="0">女</label>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label is-required">手机号码：</label>
					<div class="col-sm-8">
						<input id="userPhone" name="userPhone" placeholder="请输入手机号码" class="form-control"
						       type="text"
						       maxlength="11" required>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label is-required">邮箱：</label>
					<div class="col-sm-8">
						<input id="userEmail" name="userEmail" class="form-control email" type="text" maxlength="20"
						       placeholder="请输入邮箱" required>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label">用户状态：</label>
					<div class="col-sm-8">
						<label class="toggle-switch switch-solid" >
							<input type="checkbox" name="status" id="status" th:default="1"  checked>
							<span  id="check-box"></span>
						</label>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label">余额：</label>
					<div class="col-sm-8">
						<input type="number" name="userBalance" id="userBalance" class="form-control">
					</div>
				</div>
			</div>
		</div>
	</form>
</div>

<div class="row">
	<div class="col-sm-offset-5 col-sm-10">
		<button type="hidden" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存
		</button>&nbsp;
		<button type="hidden" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
		</button>
	</div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script>
    var prefix = ctx + "pageUser";


    function submitHandler() {
        $("#check-box").click(function () {
            if ($("#status").prop("checked")) {
                $("#status").attr("value", "1");
            } else {
                $("#status").attr("value", "0");
            }
        });


        if ($.validate.form()) {
            var data = $("#form-user-add").serializeArray();
            console.log(data);
            var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
            var roleIds = $.form.selectCheckeds("role");
            var postIds = $.form.selectSelects("post");
            data.push({"name": "status", "value": status});
            data.push({"name": "roleIds", "value": roleIds});
            data.push({"name": "postIds", "value": postIds});
            console.log(data)
            $.operate.save(prefix + "/add", data);
        }
    }

    // function submitHandler() {
	//
    //         $.operate.save(prefix + "/add", $('#form-dept-add').serializeArray());
	//
    // }


    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }

    $(function () {
        $('#post').select2({
            placeholder: "请选择岗位",
            allowClear: true
        });
    })
</script>
</body>
</html>